package com.cloudspace.yunloan.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudspace.yunloan.R;
import com.cloudspace.yunloan.YunloanApp;
import com.cloudspace.yunloan.entity.CaseEntity;
import com.cloudspace.yunloan.utils.ObjUtil;

import java.util.ArrayList;
import java.util.List;

public class FinishCaseAdapter extends BaseAdapter {
    private List<CaseEntity> finishCaseEntities;

    public void setData(List<CaseEntity> entities){
        this.finishCaseEntities = entities;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (ObjUtil.isEmpty(finishCaseEntities))
            return 0;

        return finishCaseEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(YunloanApp.getInstance()).inflate(R.layout.layout_item_case_finish, null);

            holder = new ViewHolder();
            holder.nameTv = (TextView) convertView.findViewById(R.id.name);
            holder.idCardTv = (TextView) convertView.findViewById(R.id.idcard);

            convertView.setTag(holder);
        }

        holder = (ViewHolder) convertView.getTag();

        String name = finishCaseEntities.get(position).name;
        holder.nameTv.setText(name);
        holder.idCardTv.setText(finishCaseEntities.get(position).idCard);

        return convertView;
    }

    static class ViewHolder{
        ImageView iconImg;
        TextView nameTv;
        TextView idCardTv;
    }
}
